//
//  UserModel.swift
//  travelMap
//
//  Created by green on 15/6/23.
//  Copyright (c) 2015年 com.city8. All rights reserved.
//

import ReactiveCocoa
import JSONHelper

// 用户信息
public class UserModel: NSObject, NSCoding, Deserializable {
    
    public var userId      :Int?           // ID
    public var userName    :String?        // 用户名
    public var userPicUrl  :NSURL?         // 头像地址
    public var telephone   :String?        // 手机号
    public var email       :String?        // 邮箱
    
    var userPhotoInfo: PhotoInfo?
    
    override public var description: String {
        get {
           
            return "userId:\(userId) \n userName:\(userName) \n userPicUrl:\(userPicUrl) \n telephone:\(telephone) \n email:\(email) \n --------------------------------------------------------------------- \n "
        }
    }
    
    override init() {
        
        super.init()
    
    }
    
    required public init(data : [String:AnyObject]) {
        
        super.init()
        
        userId          <-- data["userId"]
        userName        <-- data["userName"]
        userPicUrl      <-- data["userPicUrl"]
        telephone       <-- data["telephone"]
        email           <-- data["email"]
        
        if let userPicUrl=self.userPicUrl {
            
            self.userPhotoInfo = PhotoInfo(sourceImageURL: userPicUrl)
        }
    }
    
    required public init(coder decoder: NSCoder) {
        
        self.userId     = decoder.decodeObjectForKey("userId") as? Int
        self.userName   = decoder.decodeObjectForKey("userName") as? String
        self.userPicUrl = decoder.decodeObjectForKey("userPicUrl") as? NSURL
        self.telephone  = decoder.decodeObjectForKey("telephone") as? String
        self.email      = decoder.decodeObjectForKey("email") as? String
    }
    
    public func encodeWithCoder(encoder: NSCoder) {
        
        encoder.encodeObject(self.userId,forKey: "userId")
        encoder.encodeObject(self.userName,forKey: "userName")
        encoder.encodeObject(self.userPicUrl,forKey: "userPicUrl")
        encoder.encodeObject(self.telephone,forKey: "telephone")
        encoder.encodeObject(self.email, forKey: "email")
    }
    
}